<? 

class Storage
{
	private $path = null;
	private $name = null;
	
	public function Storage($path)
	{
		$dir = dirname($path);
		$this->path = $path;
		if(!is_dir($dir))
		{
			ssinc('folder');
			Folder::Create($dir);
		}
		if(!file_exists($this->path.'.list'))
		{
			file_put_contents($this->path.'.list', '');
		}
	}
	
	public function Remove($name)
	{
		exec('zip -d "'.$this->path.'" "'.$name);
		file_put_contents($this->path.'.list', str_replace("$name\n", '', file_get_contents($this->path.'.list')));
	}
	
	public function Get($name)
	{
		ob_start();
		system('unzip -p "'.$this->path.'" '.$name);
		$ret = ob_get_contents();
		ob_end_clean();
		return $ret;
	}
	public function Exists($name)
	{
		$f = fopen($this->path.'.list', 'r');
		while($s = fgets($f))
		{
			if($s == "$name\n"){ fclose($f); return true; }
		}
		fclose($f);
		return false;
		
	}
	public function Put($name, $path)
	{
		$tmp = dirname($this->path).'/'.$name;
		copy($path, $tmp);
		exec('zip -v -0 -j "'.$this->path.'" "'.$tmp.'"');
		//Log::Error('zip -v -0 -j "'.$this->path.'" "'.$tmp.'"');
		unlink($tmp);
		if(!$this->Exists($name))
		{
			$f = fopen($this->path.'.list', 'a');
			fwrite($f, "$name\n");
			fclose($f);
		}
	}
}
?>